//
//  SDShowInfoCell.m
//  SuperDoctor
//
//  Created by fdq on 16/7/7.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDShowInfoCell.h"
#import "SDPersonInfoModel.h"

@interface SDShowInfoCell()

@property (nonatomic,weak)UILabel * describtion;

@property (nonatomic,weak)UILabel * name;

@property (nonatomic,weak)UILabel * hospital;

@property (nonatomic,weak)UILabel * department;

@property (nonatomic,weak)UILabel * information;

@property (nonatomic,weak)UILabel * position;

@property (nonatomic,weak)UIImageView * imgView;

@end


@implementation SDShowInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
	
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	
	if (self) {




		//设置左侧label
		UILabel * describtion = [[UILabel alloc]init];
		
		self.describtion = describtion;
		
		[self addSubview:describtion];
		
		//姓名
		UILabel * name = [[UILabel alloc]init];
		
		self.name = name;
		
		[self.contentView addSubview:name];

		//医院名称
		UILabel * hospital = [[UILabel alloc]init];
		
		self.hospital = hospital;
		
		[self.contentView addSubview:hospital];
		
		//科室
		UILabel * department = [[UILabel alloc]init];
		
		self.department = department;
		
		[self.contentView addSubview:department];
		
		//信息描述
		UILabel * information = [[UILabel alloc]init];
		
		self.information.numberOfLines = 0;
		
		self.information.textAlignment = NSTextAlignmentLeft;
		
		self.information = information;
		
		self.information.font = [UIFont systemFontOfSize:16];
		
		self.information.textColor  = [UIColor lightGrayColor];
		
		[self addSubview:information];
		
		//职位
		UILabel * position = [[UILabel alloc]init];
		
		self.position = position;
		
		[self.contentView addSubview:self.position];
		
		//设置图片
		UIImageView * imgView = [[UIImageView alloc]init];
		
		self.imgView = imgView;
		
		[self.contentView addSubview:self.imgView];
		
//		[self setupLayout11];
	
	}
	
	return self;
	
}
-  (void)setIndexPath:(NSIndexPath *)indexPath{
	_indexPath = indexPath;

	[self setLayout];
}

- (void)setLayout{
	
	//	[super layoutSubviews];
	
	//-(void)setupLayout11{
	
	if (self.indexPath.row == 0) {
		
		//图片约束
		[self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_offset(10);
			make.centerY.mas_equalTo(self.contentView.mas_centerY);
			make.height.mas_equalTo(60);
			make.width.mas_equalTo(60);
		}];
		
		//姓名约束
		[self.name mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(self.imgView.mas_right).mas_offset(20);
			make.height.mas_equalTo(30);
			make.top.mas_offset(10);
		}];
		
		//职位约束
		[self.position mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(self.name.mas_right).mas_offset(10);
			
			make.top.mas_offset(10);
			make.height.mas_equalTo(30);
			
		}];
		
		//医院约束
		[self.hospital mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(self.imgView.mas_right).mas_offset(20);
			
			make.top.mas_equalTo(self.name.mas_bottom).mas_offset(10);
			
//			make.height.mas_equalTo(30);
			
			make.bottom.mas_offset(-5);
			
		}];
		
		//科室
		[self.department mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(self.hospital.mas_right).mas_offset(10);
			
			make.top.mas_equalTo(self.name.mas_bottom).mas_offset(10);
			
//			make.height.mas_equalTo(30);
			
		}];
	}else{
		
		
		//前面标题
		[self.describtion mas_makeConstraints:^(MASConstraintMaker *make) {
			make.top.mas_equalTo(5);
			make.left.mas_offset(10);
			//		make.right.mas_equalTo(self.information.mas_left).mas_offset(-10);
			//		make.width.mas_equalTo(50);
			make.height.mas_equalTo(23);
			
			
		}];
		
		
		int row = (int)_indexPath.row;
		
		CGFloat width = 90;
		
		if (row==2) {
			
			width = 60;
		}
		
		
		[self.information mas_remakeConstraints:^(MASConstraintMaker *make) {
			
			
			make.top.mas_equalTo(5);
			make.left.mas_equalTo(self).offset(width);
			make.right.mas_offset(-10);
			
			make.bottom.mas_offset(-5);
			
		}];
		
		
		
	}
}

- (void)setModel:(SDPersonInfoModel *)model{
	
	_model = model;
	
//	self.imgView.image = [UIImage imageNamed:model.image];
	
	self.name.text = model.name;
	
	self.position.text = model.position;
	
	self.hospital.text = model.hospital;
	
	self.department.text = model.department;
	
	self.information.numberOfLines = 0;
//	self.information.backgroundColor = [UIColor redColor];
	
	self.describtion.text = model.describtion;
	
	self.information.text = model.information;
	
}

//- (CGFloat)calculateHeight{
//	
//	CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
//	
//	CGSize maxSIze = CGSizeMake(screenWidth-CGRectGetWidth(self.describtion.frame), MAXFLOAT);
//	
//	CGFloat heightH =  [self.model.information boundingRectWithSize:maxSIze options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT(14)} context:nil].size.height;
//	
//	//	NSLog(@"height = %.2f",height);
//	
//	self.height = heightH+10+5;
//	
//	return heightH+10+5;
//}

//- (void)setIndex:(int)index{
//	_index = index;
//}

@end
